{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 通用函数：快速的元素级数组函数\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.        ,  1.        ,  1.41421356,  1.73205081,  2.        ,\n",
       "        2.23606798,  2.44948974,  2.64575131,  2.82842712,  3.        ])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.arange(10)\n",
    "np.sqrt(arr) # ufunc，作用在每个元素上"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  1.00000000e+00,   2.71828183e+00,   7.38905610e+00,\n",
       "         2.00855369e+01,   5.45981500e+01,   1.48413159e+02,\n",
       "         4.03428793e+02,   1.09663316e+03,   2.98095799e+03,\n",
       "         8.10308393e+03])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.exp(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.66825501, -0.23642231,  0.43557658,  1.67213174,  0.42920574,\n",
       "        1.88044069,  1.21284547,  1.18446622])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.random.randn(8)\n",
    "y = np.random.randn(8)\n",
    "np.maximum(x, y) # 二元函数，接受2个数组作为参数，并按对应位置进行操作。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 11.20515537  -1.96737775  -0.63960607  -1.15697875   0.05848623\n",
      "  -0.29945217  -1.37434553]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(array([ 0.20515537, -0.96737775, -0.63960607, -0.15697875,  0.05848623,\n",
       "        -0.29945217, -0.37434553]),\n",
       " array([ 11.,  -1.,  -0.,  -1.,   0.,  -0.,  -1.]))"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.random.randn(7) * 5\n",
    "print(arr)\n",
    "np.modf(arr) # 分别打印小数与整数部分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 一元ufunc\n",
    "# abs/fabs\n",
    "# sqrt\n",
    "# square\n",
    "# exp\n",
    "# log/log10/log2/log1p：log1p = log(1 + x)\n",
    "# sign\n",
    "# ceil：                向上取整\n",
    "# floor：               向下取整\n",
    "# rint：                四舍五入\n",
    "# modf：                将数组的小数和整数部分以两个独立数组的形式返回\n",
    "# isnan\n",
    "# isfinite/isinf\n",
    "# cos/cosh\n",
    "# sin/sinh\n",
    "# tan/tanh\n",
    "# arrcos/arccosh\n",
    "# arrsin/arcsinh\n",
    "# arrtan/arctanh\n",
    "# logical_not：         计算各元素not x的真值，相当于~arr。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 二元ufunc\n",
    "# add\n",
    "# subtract\n",
    "# multiply\n",
    "# divide/floor_divide\n",
    "# power\n",
    "# maximum/fmax\n",
    "# minimum/fmin\n",
    "# mod\n",
    "# copysign\n",
    "# greater/greater_equal\n",
    "# less/less_equal\n",
    "# equal/not_equal\n",
    "# logic_and/or/xor"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
